package com.mt.api.modules.controller;

import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import com.mt.api.modules.domain.bo.CustomerBillAddBo;
import com.mt.api.modules.domain.bo.CustomerBillPageBo;
import com.mt.api.modules.domain.bo.CustomerBillStatBo;
import com.mt.api.modules.domain.vo.CustomerBillVo;
import com.mt.api.modules.domain.vo.MerchantBillStatVo;
import com.mt.api.modules.service.ICustomerBillService;
import com.mt.api.util.ParamsValid;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: plover
 * @Date: 2022/04/28 16:39
 * @Description:
 */

@RestController
@RequestMapping("/app/customer/bill")
@RequiredArgsConstructor
public class CustomerBillController {

    private final ICustomerBillService customerBillService;

    @PostMapping("/add")
    @ApiOperation(value = "", notes = "客户账单添加接口", httpMethod = "GET")
    public WebResponse customerBillAdd(@RequestBody CustomerBillAddBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("请输入客户", bo.getCustomerId());
        valid.validNotNull("请输入结款金额", bo.getSettleAmount());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return customerBillService.customerBillAdd(bo);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "", notes = "客户账单详情接口", httpMethod = "GET")
    public WebResponse<CustomerBillVo> getCustomerBillDetail(Integer id) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("id不能为空", id);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return customerBillService.getCustomerBillDetail(id);
    }

    @GetMapping("/page")
    @ApiOperation(value = "", notes = "客户账单分页接口", httpMethod = "GET")
    public WebResponse getCustomerBillPage(CustomerBillPageBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("pageNum不能为空", bo.getPageNum())
                .validNotNull("pageSize不能为空", bo.getPageSize())
                .validNotNull("客户id不能为空", bo.getCustomerId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return customerBillService.getCustomerBillPage(bo);
    }

    @GetMapping("/stat")
    @ApiOperation(value = "", notes = "客户账单统计接口", httpMethod = "GET")
    public WebResponse<MerchantBillStatVo> getCustomerBillStat(CustomerBillStatBo bo) {
        return customerBillService.getCustomerBillStat(bo);
    }

}
